package club.zhangliyuanblog.service.impl;

import club.zhangliyuanblog.dao.UserDao;
import club.zhangliyuanblog.entity.User;
import club.zhangliyuanblog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * @author liyuan.zhang
 * @date 2021/2/18 22:59
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    // ToDo 为什么
    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public void save(User user) {
        userDao.save(user);
    }

    @Override
    public void deleteUserById(Integer id) {
        userDao.deleteUserById(id);
    }

    @Override
    public void update(User user) {
        userDao.updateUser(user);
    }

    @Override
    public List<User> findUserByPage(Integer pageNow, Integer rows) {
        int start = (pageNow - 1) * rows;
        return userDao.findUserByPage(start,rows);
    }

    @Override
    public Long findTotals() {
        return userDao.findTotals();
    }

    @Override
    public void batchInsertUser(List<User> users) {
        int i = userDao.batchInsertUser(users);
        System.out.println("影响" + i + "行数据");
    }
}
